/**
*		SilverMapper v1.0.0
*		lastmodified: November 10th, 2008
*		author: Michael Giddens
*		company: SilverBiology
*		website: www.SilverBiology.com
*
*		This file is part of SilverMapper.
*
*		SilverMapper is free software: you can redistribute it and/or modify
*		it under the terms of the GNU General Public License as published by
*		the Free Software Foundation, either version 3 of the License, or
*		(at your option) any later version.
*	
*		SilverMapper is distributed in the hope that it will be useful,
*		but WITHOUT ANY WARRANTY; without even the implied warranty of
*		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*		GNU General Public License for more details.
*	
*		You should have received a copy of the GNU General Public License
*		along with SilverMapper.  If not, see <http://www.gnu.org/licenses/>.
*/
	
Ext.onReady(function() {

	Ext.QuickTips.init();

	// Disable browser right click
	Ext.fly(document.body).on('contextmenu', function(e, target) {
		e.preventDefault();
	});	

	// Needed to set css mask
	Ext.BLANK_IMAGE_URL = "images/s.gif";	

	Ext.get('loading').remove();
	Ext.get('loading-mask').fadeOut({remove:true});

	// Initalize SilverMapper Object
	var sm = new SilverMapper();

	/**
	*		LAYERS
	*		Here is where layers are added. All layers must have a different
	*		layer id and correspond to layer images, css, and serverside code.
	*
	*		text: title for the layer
	*		checked: will set the default state of the layer. (true/false)
	**/

	// Layers for Mapper
	var node = new Ext.tree.TreeNode({
			text: 'Univ. of Washington Herbarium (Introduced)'
		,	checked: true
		,	iconCls: 'layer_0_single'
		,	layer_id: 0
		,	listeners: {
				'checkchange': function() {
					sm.map.layerChange();
				}
			}
	});

	// This adds the layer to the application
	sm.layers.getRootNode().appendChild( node );

	// Layers for Mapper
	var node = new Ext.tree.TreeNode({
			text: 'Univ. of Washington Herbarium (Native)'
		,	checked: false
		,	iconCls: 'layer_2_single'
		,	layer_id: 2
		,	listeners: {
				'checkchange': function() {
					sm.map.layerChange();
				}
			}
	});

	// This adds the layer to the application
	sm.layers.getRootNode().appendChild( node );

	node = new Ext.tree.TreeNode({
			text: 'Noxious Weed Observations'
		,	checked: true
		,	iconCls: 'layer_1_single'
		,	layer_id: 1
		,	listeners: {
				'checkchange': function() {
					sm.map.layerChange();
				}
			}
	});

	sm.layers.getRootNode().appendChild( node );

	/**
	* 	Setup Listeners 
	*		(Note: You do not have to change this code)
	**/

	// Add listener to show the Lat/Lng of where the mouse is on the map.
	GEvent.addListener(sm.map.gmap, "mousemove", function(point) {
		var latLngStr = point.lat().toFixed(4) + ', ' + point.lng().toFixed(4);		
		Ext.getCmp('sm-map-statusbar').setText( Lang.Get('Core','general','coordinates') + latLngStr );
	});
	
	// Add listener to refresh when the map is finished being dragged.
	GEvent.bind( sm.map.gmap, "dragend", this, function() {
	 	sm.map.getMarkers( 1 );
	});

	// Add listener to refresh map when the map is zoomed in or out.
	GEvent.bind( sm.map.gmap, "zoomend", this, function() {
		sm.map.getMarkers( 1 );
	});

});